package com.yami.shop.search.common.listener;

import com.yami.shop.bean.enums.EsOperationType;
import com.yami.shop.bean.event.EsHotWordsUpdateEvent;
import com.yami.shop.bean.event.EsProductUpdateEvent;
import com.yami.shop.search.common.service.EsHotWordsService;
import com.yami.shop.search.common.service.EsMysteryBoxService;
import com.yami.shop.search.common.service.EsProductService;
import com.yami.shop.service.UserSearchHistoryService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 获取es数据事件
 * @author yami
 */
@Component("EsHotWordsUpdateListener")
@AllArgsConstructor
public class EsHotWordsUpdateListener {

    private final EsHotWordsService esHotWordsService;
    @EventListener(EsHotWordsUpdateEvent.class)
    @Async
    public void defaultEsProductListener(EsHotWordsUpdateEvent event) throws InterruptedException {
        // 保证商品添加完成数据库查的到
        EsOperationType esOperationType = event.getEsOperationType();
        Long id = event.getId();
        // 保存
        if (Objects.equals(esOperationType, EsOperationType.SAVE)) {
            esHotWordsService.save(id);
        }

    }
}
